app.controller('BusStationListCtrl', function($scope, ajax, $modal, toaster) {

    var querier = new Req.GET({
        page_index: 1,
        resource: $scope.resource
    });
    var inserter = new Req.POST({ resource: $scope.resource });
    var deleter = new Req.DELETE({ resource: $scope.resource });
    var updater = new Req.PUT({ resource: $scope.resource });


    $scope.reload = $scope.page.loader('station/bs/{pageIndex}/{pageSize}/page');
    $scope.$on('pageIndex', function(event, p) { $scope.reload(p, $scope.queryMap); });
    $scope.reload(1);
    $scope.queryMap = {};
    $scope.query = function() { $scope.reload(1, $scope.queryMap); };

	// 新增、更新
	$scope.write = function (size, current_data, submit_type) {
		$scope.current_data = angular.copy(current_data);
		var modalInstance = $modal.open({
			templateUrl: 'template/bus/station/update.html?v=84c01c1bbe',
			controller: 'BusStationUpdateCtrl',
			size: size,
			resolve: {
				param: function () {
					return {
						"data": $scope.current_data,
						"type": submit_type
					};
				}
			}
		});

		modalInstance.result.then(function (param) {
			if (param.type == 'update') {
				updater.fields = param.data;
				updater.id = param.data.id;
				updater.resource = 'station/bs/update';
				$scope.page.mod(updater, $scope.reload);
			} 
		});
	};

    //删除
    $scope.del = function(size, current_data, submit_type) {
		var modalInstance = $scope.delModal(size, current_data, submit_type);
        modalInstance.result.then(function(param) {
            if (param.type == 'delete') {
                deleter.id = param.data.id;
                deleter.resource = 'station/bs/' + deleter.id + '/delete';
                $scope.page.del(deleter, $scope.reload);
            }
        });
    };


});
